﻿using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OperateDatabaseLibTest.SqlServer.Fixtures.CollectionFixtures
{
    /// <summary>
    /// SqlServer夹具类
    /// </summary>
    public class SqlServerFixture : IDisposable
    {
        /// <summary>
        /// 数据库连接对象
        /// </summary>
        private readonly SqlConnection conn;

        /// <summary>
        /// 构造函数
        /// </summary>
        public SqlServerFixture()
        {
            var connStrBuilder = new SqlConnectionStringBuilder
            {
                DataSource = "localhost\\SQLEXPRESS",
                //InitialCatalog = "EFTestDB",
                IntegratedSecurity = false,
                UserID = "sa",
                Password = "123",
                TrustServerCertificate = true
            };
            conn = new SqlConnection(connStrBuilder.ConnectionString);
            conn.Open();
        }

        /// <summary>
        /// 数据库连接对象属性
        /// </summary>
        public SqlConnection SqlConnection => conn;

        /// <summary>
        /// 释放非托管资源
        /// </summary>
        public void Dispose()
        {
            conn.Dispose();
        }
    }
}
